package cn.iocoder.yudao.module.handguard.service.userbasetable3;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.handguard.controller.app.userbasetable3.vo.*;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userbasetable3.UserBaseTable3DO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.handguard.convert.userbasetable3.UserBaseTable3Convert;
import cn.iocoder.yudao.module.handguard.dal.mysql.userbasetable3.UserBaseTable3Mapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.handguard.enums.ErrorCodeConstants.*;

/**
 * 个人贴息贷 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class UserBaseTable3ServiceImpl implements UserBaseTable3Service {

    @Resource
    private UserBaseTable3Mapper userBaseTable3Mapper;

    @Override
    public Long createUserBaseTable3(UserBaseTable3CreateReqVO createReqVO) {
        // 插入
        UserBaseTable3DO userBaseTable3 = UserBaseTable3Convert.INSTANCE.convert(createReqVO);
        userBaseTable3Mapper.insert(userBaseTable3);
        // 返回
        return userBaseTable3.getId();
    }

    @Override
    public void updateUserBaseTable3(UserBaseTable3UpdateReqVO updateReqVO) {
        // 校验存在
        validateUserBaseTable3Exists(updateReqVO.getId());
        // 更新
        UserBaseTable3DO updateObj = UserBaseTable3Convert.INSTANCE.convert(updateReqVO);
        userBaseTable3Mapper.updateById(updateObj);
    }

    @Override
    public void deleteUserBaseTable3(Long id) {
        // 校验存在
        validateUserBaseTable3Exists(id);
        // 删除
        userBaseTable3Mapper.deleteById(id);
    }

    private void validateUserBaseTable3Exists(Long id) {
        if (userBaseTable3Mapper.selectById(id) == null) {
            throw exception(USER_BASE_TABLE3_NOT_EXISTS);
        }
    }

    @Override
    public UserBaseTable3DO getUserBaseTable3(Long id) {
        LambdaQueryWrapper<UserBaseTable3DO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserBaseTable3DO::getApplicationId,id);
        return userBaseTable3Mapper.selectOne(queryWrapper);
    }

    @Override
    public List<UserBaseTable3DO> getUserBaseTable3List(Collection<Long> ids) {
        return userBaseTable3Mapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<UserBaseTable3DO> getUserBaseTable3Page(UserBaseTable3PageReqVO pageReqVO) {
        return userBaseTable3Mapper.selectPage(pageReqVO);
    }

    @Override
    public List<UserBaseTable3DO> getUserBaseTable3List(UserBaseTable3ExportReqVO exportReqVO) {
        return userBaseTable3Mapper.selectList(exportReqVO);
    }

}
